<?php

namespace app\api\controller\product;

use app\api\model\product\Category as CategoryModel;
use app\api\controller\Controller;
use app\api\model\product\Product as ProductModel;
use app\common\model\page\PageCategory as PageCategoryModel;
use app\api\model\ad\Ad as AdModel;
/**
 * 商品分类控制器
 */
class Category extends Controller
{
    /**
     * 分类页面
     */
    public function index()
    {
        // 分类模板
        //$template = PageCategoryModel::detail();
        // 商品分类列表
        $list = CategoryModel::getCacheAll();

        // 整理请求的参数
        $param = [
            'product_status' => 10,
            'sortType'=>'category',
        ];


        // 获取列表数据
        $model = new ProductModel;
        $products = $model->getList($param, $this->getUser(false));

        foreach ($list as &$category){
                $category['products'] = [];
        }
        foreach ($products as $product){
            foreach ($list as &$category){
                if($category['category_id'] == $product['category_id']){
                    array_push($category['products'], $product);
                }
            }
        }
        //点餐广告
        //$Admodel = new AdModel;
        //$adList = $Admodel->getIndex(array('category_id'=>$category_id,'status'=>1),5);
        return $this->renderSuccess('', compact('list'));
    }

}